﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DataVisualization
{
    public partial class TextWindow : Form
    {
        DataGridView dataSet;
        private List<Int64> columnCount;

        public TextWindow()
        {
            dataSet = null;
            InitializeComponent();
            columnCount = new List<Int64>();
        }
        public TextWindow(DataGridView infoSet)
        {
            InitializeComponent();
            dataSet = infoSet;
            columnCount = new List<Int64>();

            for (int i = 0; i < dataSet.Columns.Count; ++i)
            {
                columnCount.Add(countUniqueItems(i));
            }
            dataGrid.Columns.Add("InfoType", "InfoType");
            foreach (DataGridViewColumn column in dataSet.Columns)
            {
                dataGrid.Columns.Add(column.HeaderText, column.HeaderText);
            }
            List<string> uniqueItemRow = new List<string>();
            uniqueItemRow.Add("Unique Items");
            foreach (Object item in columnCount)
            {
                uniqueItemRow.Add(item.ToString());
            }
            dataGrid.Rows.Add(uniqueItemRow.ToArray());
        }

        private Int64 countUniqueItems(int columnNumber)
        {
            List<string> searchedValues = new List<string>();
            Int64 totalUnique = -1;
            foreach (DataGridViewRow row in dataSet.Rows)
            {
                string cellString = (string)row.Cells[columnNumber].Value;
                if (!searchedValues.Contains(cellString))
                {
                    totalUnique++;
                    searchedValues.Add(cellString);
                }
            }
            return totalUnique;
        }
    }
}
